package misc

import (
	"time"
)

var (
	GTimer Timer
)

func init() {
	GTimer = Timer{}
	GTimer.StartSecondTimer()

}

type Timer struct {
	Now   time.Time //当前时间，精确到秒
	Unix  int64     //当前时间戳
	Stime string    //当前时间
}

func (p *Timer) updateCurtime() {
	p.Unix = p.Now.Unix()
	p.Stime = FormatTime(p.Now)
}

func (p *Timer) StartSecondTimer() {
	p.Now = time.Now()
	p.updateCurtime()
	go func() {
		for {
			cur := <-time.After(time.Second)
			p.Now = cur
			p.updateCurtime()
		}
	}()
}
